Apply --all if workspace is virtual
authorRomain Sertelon <romain@sertelon.fr>
Wed, 10 May 2017 21:30:32 +0000 (23:30 +0200)
committerdebris <marek.kotewicz@gmail.com>
Thu, 27 Jul 2017 19:45:28 +0000 (21:45 +0200)
Should help close #4021

src/bin/bench.rs
src/bin/build.rs
src/bin/check.rs
src/bin/doc.rs
src/bin/test.rs
src/cargo/core/workspace.rs

index ff1e0b4e7baee1ec58f36b0eed067753cd6d9165..31004a2d4cf65c8d4a4a944d09c0ce7bcfc8d18f 100644 (file)
@@ -1,3 +1,5 @@
+use std::env;
+
 use cargo::core::Workspace;
 use cargo::ops::{self, MessageFormat, Packages};
 use cargo::util::{CliResult, CliError, Config, CargoErrorKind};
@@ -88,17 +90,26 @@ Compilation can be customized with the `bench` profile in the manifest.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult {
-    let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
-
-    let spec = Packages::from_flags(options.flag_all,
-                                    &options.flag_exclude,
-                                    &options.flag_package)?;
+    debug!("executing; cmd=cargo-bench; args={:?}",
+           env::args().collect::<Vec<_>>());
 
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
                      options.flag_frozen,
                      options.flag_locked)?;
+
+    let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
+    let ws = Workspace::new(&root, config)?;
+
+    let spec = if options.flag_all || ws.is_virtual() {
+        Packages::All
+    } else {
+        Packages::from_flags(options.flag_all,
+                            &options.flag_exclude,
+                            &options.flag_package)?
+    };
+
     let ops = ops::TestOptions {
         no_run: options.flag_no_run,
         no_fail_fast: options.flag_no_fail_fast,
@@ -124,7 +135,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
         },
     };
 
-    let ws = Workspace::new(&root, config)?;
     let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
     match err {
         None => Ok(()),
index c679fc50f067673fe9f3be8f353e2a69ac02fa5a..9f0757aa368b499f60c04226c90708bb2a6371aa 100644 (file)
@@ -92,10 +92,15 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
                      options.flag_locked)?;
 
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
+    let ws = Workspace::new(&root, config)?;
 
-    let spec = Packages::from_flags(options.flag_all,
-                                    &options.flag_exclude,
-                                    &options.flag_package)?;
+    let spec = if options.flag_all || ws.is_virtual() {
+        Packages::All
+    } else {
+       Packages::from_flags(options.flag_all,
+                               &options.flag_exclude,
+                               &options.flag_package)?
+    };
 
     let opts = CompileOptions {
         config: config,
@@ -117,7 +122,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
         target_rustc_args: None,
     };
 
-    let ws = Workspace::new(&root, config)?;
     ops::compile(&ws, &opts)?;
     Ok(())
 }
index fd36f5420009fb87f84cf675effb93e8ef3e1c31..03c15e624971561f878ad327f98094d3825e66b6 100644 (file)
@@ -91,9 +91,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
     let ws = Workspace::new(&root, config)?;
 
-    let spec = Packages::from_flags(options.flag_all,
-                                    &options.flag_exclude,
-                                    &options.flag_package)?;
+    let spec = if options.flag_all || ws.is_virtual() {
+        Packages::All
+    } else {
+       Packages::from_flags(options.flag_all,
+                            &options.flag_exclude,
+                            &options.flag_package)?
+    };
 
     let opts = CompileOptions {
         config: config,
index 6b4190985df2ceca07d9b029d576a5908d01bc01..cfa1116d88fd5801a93225e569eac295ba6140ed 100644 (file)
@@ -1,3 +1,5 @@
+use std::env;
+
 use cargo::core::Workspace;
 use cargo::ops::{self, MessageFormat, Packages};
 use cargo::util::{CliResult, Config};
@@ -69,6 +71,9 @@ the `cargo help pkgid` command.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult {
+    debug!("executing; cmd=cargo-check; args={:?}",
+           env::args().collect::<Vec<_>>());
+
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -76,8 +81,9 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
                      options.flag_locked)?;
 
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
+    let ws = Workspace::new(&root, config)?;
 
-    let spec = if options.flag_all {
+    let spec = if options.flag_all || ws.is_virtual() {
         Packages::All
     } else {
         Packages::Packages(&options.flag_package)
@@ -109,7 +115,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
         },
     };
 
-    let ws = Workspace::new(&root, config)?;
     ops::doc(&ws, &doc_opts)?;
     Ok(())
 }
index fe8d5757f8c3081af7797fb175b3d9791d383b6b..daef1e472236d4b4b41bcf61143c59c47a329ac0 100644 (file)
@@ -1,3 +1,5 @@
+use std::env;
+
 use cargo::core::Workspace;
 use cargo::ops::{self, MessageFormat, Packages};
 use cargo::util::{CliResult, CliError, Config, CargoErrorKind};
@@ -109,6 +111,9 @@ To get the list of all options available for the test binaries use this:
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult {
+    debug!("executing; cmd=cargo-test; args={:?}",
+           env::args().collect::<Vec<_>>());
+
     config.configure(options.flag_verbose,
                      options.flag_quiet,
                      &options.flag_color,
@@ -116,6 +121,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
                      options.flag_locked)?;
 
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
+    let ws = Workspace::new(&root, config)?;
 
     let empty = Vec::new();
     let (mode, filter);
@@ -132,9 +138,13 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
                                          &options.flag_bench, options.flag_benches);
     }
 
-    let spec = Packages::from_flags(options.flag_all,
-                                    &options.flag_exclude,
-                                    &options.flag_package)?;
+    let spec = if options.flag_all || ws.is_virtual() {
+        Packages::All
+    } else {
+       Packages::from_flags(options.flag_all,
+                            &options.flag_exclude,
+                            &options.flag_package)?
+    };
 
     let ops = ops::TestOptions {
         no_run: options.flag_no_run,
@@ -157,7 +167,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
         },
     };
 
-    let ws = Workspace::new(&root, config)?;
     let err = ops::run_tests(&ws, &ops, &options.arg_args)?;
     match err {
         None => Ok(()),
index 5f93baa856b6d1a7c8cccccabe4c8651380e004f..ad53fc5b5c94ab75ceeace5a05b402c31d02a23f 100644 (file)
@@ -179,6 +179,13 @@ impl<'cfg> Workspace<'cfg> {
         }
     }
 
+    pub fn is_virtual(&self) -> bool {
+        match *self.packages.get(&self.current_manifest) {
+            MaybePackage::Package(..) => false,
+            MaybePackage::Virtual(..) => true
+        }
+    }
+
     /// Returns the `Config` this workspace is associated with.
     pub fn config(&self) -> &'cfg Config {
         self.config